package com.carkeeper.serve.controller;


import com.carkeeper.entity.Result;
import com.carkeeper.feign.KnowledgeFeign;
import com.carkeeper.pojo.KnowledgeBaseInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/knowledgeWeb")
public class KnowledgeController {


    @Autowired
    private KnowledgeFeign knowledgeFeign;


    /**
     * 创建索引库
     * @return
     */
    @GetMapping("/createES")
    public Result createElasticsearch() {
        return knowledgeFeign.createElasticsearch();
    }


    /**
     * 批量导入
     * @return
     */
    @PostMapping("/batchAdd")
    public Result batchSingleAddES() {
        return knowledgeFeign.batchSingleAddES();
    }


    /**
     * 多条件查询
     * @param map
     * @return
     */
    @GetMapping("/showAllKnowledge/{currentPage}/{pageSize}")
    public Result<List<KnowledgeBaseInfo>> showAllKnowledge(@PathVariable("currentPage") String currentPage,@PathVariable("pageSize") String pageSize,@RequestParam Map map) {
        return knowledgeFeign.showAllKnowledge(map,currentPage,pageSize);
    }


    /**
     * 查询全部分类
     * @param map
     * @return
     */
    @GetMapping("/showCategory")
    public Result<Map<String,List<String>>> findCategory(@RequestParam Map map) {
        return knowledgeFeign.findCategory(map);
    }


    /**
     * 添加推文
     *
     * @return
     */
    @PostMapping("/add")
    public Result add(KnowledgeBaseInfo knowledgeBaseInfo) {
        return knowledgeFeign.addKnowledgeBaseInfo(knowledgeBaseInfo);
    }



    /**
     * 更新推文
     *
     * @param knowledgeBaseInfo
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody KnowledgeBaseInfo knowledgeBaseInfo){
        return knowledgeFeign.update(knowledgeBaseInfo);
    }


    /**
     * 删除推文
     * @param id
     * @return
     */
    @DeleteMapping("/del/{id}")
    public Result delete(@PathVariable("id") Long id) {
        return knowledgeFeign.delete(id);
    }



}
